package com.lxl.hadoop.flowsum;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2021/12/6 19:53
 * @Description
 */
public class FlowReducer extends Reducer<LongWritable, FlowBean,LongWritable, FlowBean> {
    FlowBean v = new FlowBean();
    protected void reduce(LongWritable key, Iterable<FlowBean> values,
                          Context context) throws IOException, InterruptedException {
        long upFlow =0L;
        long downFlow =0L;
        for(FlowBean value: values) {
             upFlow += value.getUpFlow();
             downFlow += value.getDownFlow();
        }
        v.setUpFlow(upFlow);
        v.setDownFlow(downFlow);
        v.setSumFlow(upFlow+downFlow);
        context.write(key,v);
    }
}
